﻿using HBKY.Shop.Common.Helper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using System;
using System.ComponentModel;

namespace HBKY.Shop.Extensions.Attribute
{
    /// <summary>
    /// 自定义路由 /api/{version}/[controler]/[action]
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
    public class CustomRouteAttribute : RouteAttribute, IApiDescriptionGroupNameProvider
    {
        /// <summary>
        /// 分组名称,是来实现接口 IApiDescriptionGroupNameProvider
        /// </summary>
        public string GroupName { get; set; }

        /// <summary>
        /// 自定义路由构造函数，继承基类路由
        /// </summary>
        /// <param name="actionName"></param>
        public CustomRouteAttribute(string actionName = "[controller]") : base($"{Appsettings.Option("Startup", "RoutePrefix")}/api/{actionName}/")
        {
        }

        /// <summary>
        /// 自定义版本+路由构造函数，继承基类路由
        /// </summary>
        /// <param name="actionName"></param>
        /// <param name="version"></param>
        public CustomRouteAttribute(ApiGroup group, string actionName = "") : base(
            $"{Appsettings.Option("Startup", "RoutePrefix")}/api/{group.ToString().ToLower()}/")
        {
            GroupName = group.ToString();
        }
    }

    /// <summary>
    /// Api接口版本 自定义
    /// </summary>
    public enum ApiGroup
    {
        //[Description("对外服务")] External = 1,
        //[Description("电报服务")] Telegraph = 1,
        //[Description("对内服务")] Internal,
        [Description("V1")] V1,
    }
}